package com.mb.app.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.domain.TbIndexProductInfo;
import com.mb.app.dao.TbIndexProductInfoMapper;
import com.mb.app.service.ITbIndexProductInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 首页商品信息  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-04-03
 */
@Service
@Slf4j
public class TbIndexProductInfoServiceImpl extends ServiceImpl<TbIndexProductInfoMapper, TbIndexProductInfo> implements ITbIndexProductInfoService {


    @Override
    public List<TbIndexProductInfo> queryList(Map<String, Object> map) {
        List<TbIndexProductInfo> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.countt(map);
    }

    @Override
    public int save(TbIndexProductInfo TbIndexProductInfo) {
        TbIndexProductInfo.setCreateTime(new Date());
        return this.baseMapper.insert(TbIndexProductInfo);
    }

    @Override
    public int update(TbIndexProductInfo TbIndexProductInfo) {
        try {
            TbIndexProductInfo.setUpdateTime(new Date());
            this.baseMapper.updateById(TbIndexProductInfo);
        } catch (Exception e) {
            log.error("update Exception", e);
        }
        return 0;
    }


    @Override
    public int remove(Long bannerId, Long delUserId) {
//        return this.baseMapper.deleteById(appId);
        TbIndexProductInfo TbIndexProductInfo = new TbIndexProductInfo();
        TbIndexProductInfo.setId(bannerId);
        TbIndexProductInfo.setDeleteTime(new Date());
        TbIndexProductInfo.setDataStatus(0);
        TbIndexProductInfo.setDeleteUserId(delUserId);
        return this.baseMapper.updateById(TbIndexProductInfo);
    }

    @Override
    public TbIndexProductInfo getDtl(Long bannerId) {
        TbIndexProductInfo TbIndexProductInfo = this.baseMapper.selectByIds(bannerId);
        return TbIndexProductInfo;
    }

    @Override
    public boolean indexProductNameExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectByIndexProductInfo(params).size() > 0;
        return exit;
    }


    @Override
    public List<TbIndexProductInfo> queryListTop(Map<String, Object> map) {
        List<TbIndexProductInfo> list = this.baseMapper.lstTop(map);
        return list;
    }

    @Override
    public int countTop(Map<String, Object> map) {
        return this.baseMapper.counttTop(map);
    }

    @Override
    public TbIndexProductInfo getDtlTop(Long bannerId) {
        TbIndexProductInfo TbIndexProductInfo = this.baseMapper.selectByIdTops(bannerId);
        return TbIndexProductInfo;
    }
}
